<template>
  <div class="container">
    <van-nav-bar
  title="注册页面"
/>
    <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">提交</van-button>
  </div>
</van-form>
<router-link to="/login" class="link">已有账号，立即登录</router-link>
  </div>
</template>

<script>

import { register } from '@/api/user'
export default {
name:'LoginIndex',
data() {
    return {
      username: '',
      password: '',
    };
  },

  methods: {
   async onSubmit(values) {
    // console.log(values)
   const res= await register(values)
  //  console.log(res)
   if(res.data.status===400){
   return this.$toast('用户名已被注册')
   }
    this.$toast('注册成功')
    this.$router.push('/login')
    },
  },

}
</script>

<style scoped lang="less">
body{
  height: 100%;
  background-color: #f8f8f8;
}
.van-form{
  margin-top: 50%;
}

.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  // float: right;
  margin-left: 35%;
}
</style>
